package com.client.ryt.task.http.response;


import com.client.ryt.basic.BaseResponse;
import com.client.ryt.entity.exception.JsonException;
import com.client.ryt.entity.exception.RemoteDataException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;


/**
 * Created by Administrator on 2014/7/12.
 */
public class TradeRecordInfoResponse extends BaseResponse {

    String shop_title;
    String card_title;
    String follow_id;
    String trade_time;
    String trade_goods;


    public TradeRecordInfoResponse(){super(null);}
    public TradeRecordInfoResponse(JSONObject json) {
        super(json);
        try {
            if(this.getIsSuccess()){
                JSONObject msg = json.getJSONObject("msg");
                shop_title = msg.getString("shop_title");
                card_title = msg.getString("card_title");
                follow_id = msg.getString("follow_id");
                trade_time = msg.getString("trade_time");
                JSONArray goods = msg.getJSONArray("goods");
                String goodsString = "";
                for(int i=0;i<goods.length();i++){
                    JSONObject jo = goods.getJSONObject(i);
                    goodsString+=jo.getString("title")+",";
                }
                if(goodsString.indexOf(",") != -1){
                    goodsString = goodsString.substring(0,goodsString.length()-1);
                }
                trade_goods = goodsString;
            }else{
                this.setBaseException(new RemoteDataException(json));
            }
        } catch (JSONException e) {
            this.setBaseException(new JsonException(e.getMessage()));
        }
    }

    public String getShop_title() {
        return shop_title;
    }

    public String getCard_title() {
        return card_title;
    }

    public String getFollow_id() {
        return follow_id;
    }

    public String getTrade_time() {
        return trade_time;
    }

    public String getTrade_goods() {
        return trade_goods;
    }
}
